package demo.generator;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

/**
 * 自定义的Mysql->Java类型转换器<br/>
 * 通过自定义完善mybatis-plus提供的转换器
 */
public class MyMsqlTypeConvert extends MySqlTypeConvert {

    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        String t = fieldType.toLowerCase();
        // unsigned int -> Long
        if (t.matches("int\\(\\d+\\) unsigned")) {
            return DbColumnType.LONG;
        } else {
            return super.processTypeConvert(globalConfig, fieldType);
        }
    }
}
